package com.ruoyi.basedata.service.impl;

import java.util.Arrays;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.basedata.mapper.BillPaymentRecordMapper;
import com.ruoyi.basedata.domain.BillPaymentRecord;
import com.ruoyi.basedata.service.IBillPaymentRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
/**
 * 缴费记录Service业务层处理
 * 
 * @author gdqt
 * @date 2025-04-23
 */
@Service
public class BillPaymentRecordServiceImpl extends ServiceImpl<BillPaymentRecordMapper, BillPaymentRecord> implements IBillPaymentRecordService
{
    @Autowired
    private BillPaymentRecordMapper billPaymentRecordMapper;

    /**
     * 查询缴费记录
     * 
     * @param id 缴费记录主键
     * @return 缴费记录
     */
    @Override
    public BillPaymentRecord selectBillPaymentRecordById(Long id)
    {

        return billPaymentRecordMapper.selectById(id);
    }

    /**
     * 查询缴费记录列表
     * 
     * @param billPaymentRecord 缴费记录
     * @return 缴费记录
     */
    @Override
    public List<BillPaymentRecord> selectBillPaymentRecordList(BillPaymentRecord billPaymentRecord)
    {
        LambdaQueryWrapper<BillPaymentRecord> queryWrapper = new LambdaQueryWrapper<>();
        if(!StringUtils.isEmpty(billPaymentRecord.getEnergyUseClassification())){
            queryWrapper.eq(BillPaymentRecord::getEnergyUseClassification,billPaymentRecord.getEnergyUseClassification());
        }
        if(!StringUtils.isEmpty(billPaymentRecord.getUserId())){
            queryWrapper.eq(BillPaymentRecord::getUserId,billPaymentRecord.getUserId());
        }
        if(!StringUtils.isEmpty(billPaymentRecord.getTerminalId())){
            queryWrapper.eq(BillPaymentRecord::getTerminalId,billPaymentRecord.getTerminalId());
        }
        if(billPaymentRecord.getPaymentType() != null){
            queryWrapper.eq(BillPaymentRecord::getPaymentType,billPaymentRecord.getPaymentType());
        }
        if(billPaymentRecord.getBeforePrice() != null){
            queryWrapper.eq(BillPaymentRecord::getBeforePrice,billPaymentRecord.getBeforePrice());
        }
        if(billPaymentRecord.getRechargePrice() != null){
            queryWrapper.eq(BillPaymentRecord::getRechargePrice,billPaymentRecord.getRechargePrice());
        }
        if(!StringUtils.isEmpty(billPaymentRecord.getWriteOffMonths())){
            queryWrapper.eq(BillPaymentRecord::getWriteOffMonths,billPaymentRecord.getWriteOffMonths());
        }
        if(billPaymentRecord.getWriteOffPrice() != null){
            queryWrapper.eq(BillPaymentRecord::getWriteOffPrice,billPaymentRecord.getWriteOffPrice());
        }
        if(billPaymentRecord.getCurrentPrice() != null){
            queryWrapper.eq(BillPaymentRecord::getCurrentPrice,billPaymentRecord.getCurrentPrice());
        }
        if(billPaymentRecord.getPaymentTime() != null){
            queryWrapper.eq(BillPaymentRecord::getPaymentTime,billPaymentRecord.getPaymentTime());
        }
        if(billPaymentRecord.getPaymentSource() != null){
            queryWrapper.eq(BillPaymentRecord::getPaymentSource,billPaymentRecord.getPaymentSource());
        }
        if(billPaymentRecord.getStatus() != null){
            queryWrapper.eq(BillPaymentRecord::getStatus,billPaymentRecord.getStatus());
        }
        if(billPaymentRecord.getOperator() != null){
            queryWrapper.eq(BillPaymentRecord::getOperator,billPaymentRecord.getOperator());
        }
        return billPaymentRecordMapper.selectList(queryWrapper);
    }

    /**
     * 新增缴费记录
     * 
     * @param billPaymentRecord 缴费记录
     * @return 结果
     */
    @Override
    public int insertBillPaymentRecord(BillPaymentRecord billPaymentRecord)
    {
        return billPaymentRecordMapper.insert(billPaymentRecord);
    }

    /**
     * 修改缴费记录
     * 
     * @param billPaymentRecord 缴费记录
     * @return 结果
     */
    @Override
    public int updateBillPaymentRecord(BillPaymentRecord billPaymentRecord)
    {
        billPaymentRecord.setUpdateTime(DateUtils.getNowDate());
        return billPaymentRecordMapper.updateById(billPaymentRecord);
    }

    /**
     * 批量删除缴费记录
     * 
     * @param ids 需要删除的缴费记录主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteBillPaymentRecordByIds(Long[] ids)
    {
        return billPaymentRecordMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除缴费记录信息
     * 
     * @param id 缴费记录主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteBillPaymentRecordById(Long id)
    {
        return billPaymentRecordMapper.deleteById(id);
    }
}
